package constellation.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import androidx.fragment.app.Fragment;

import com.example.myapplication.R;
import com.google.gson.Gson;

import java.util.List;

import constellation.adapter.StartItemGridviewAdapter;
import constellation.util.AssetsUtil;
import constellation.util.StartInfo;

/**
 * A simple {@link Fragment} subclass.
 */
public class luckFragment extends Fragment {
    View view;
    Context context;
    private GridView luckGridview;
    StartItemGridviewAdapter adapter;
    public luckFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_luck, container, false);
        luckGridview = (GridView) view.findViewById(R.id.luck_gridview);
        context = getContext();
        initData();
        return view;
    }
    public void initData(){
        String json= AssetsUtil.getJsonByAssets(getContext(),"xzcontent/xzcontent.json");
        //将json字符串转换成创建类的对象
        Gson gson=new Gson();
        StartInfo starInfo = gson.fromJson(json, StartInfo.class);
        List<StartInfo.StarinfoBean> list=starInfo.getStarinfo();
        adapter=new StartItemGridviewAdapter(context,list);
        luckGridview.setAdapter(adapter);
    }

}
